﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Menu.aspx.cs" Inherits="Menu" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cphAYNI" runat="Server">
    <script type="text/javascript" src="../../js/JQGridReq/grid.locale-en.js"></script>
    <script type="text/javascript" src="../../js/JQGridReq/jquery.jqGrid.js"></script>
    <link href="../../js/JQGridReq/jquery-ui-1.9.2.custom.css" rel="stylesheet" />
    <link href="../../js/JQGridReq/ui.jqgrid.css" rel="stylesheet" />

    <%--<table id="treegrid">
    </table>--%>

    <script type="text/javascript">
        var mydata = [
    {
        id: "1", name: "Seguridad", num: "100", enbl: "1",
        level: "0", parent: "", isLeaf: false, expanded: false, loaded: true
    },
    {
        id: "2", name: "Registro de Usuarios", num: "1", enbl: "0",
        level: "1", parent: "1", isLeaf: false, expanded: false, loaded: true
    },
    {
        id: "3", name: "Clientes", num: "1", enbl: "1",
        level: "2", parent: "2", isLeaf: true, expanded: false, loaded: true
    },
    {
        id: "4", name: "Cash 2", num: "2", enbl: "0",
        level: "1", parent: "1", isLeaf: true, expanded: false, loaded: true
    },
    {
        id: "5", name: "Bank\'s", num: "200", enbl: "1",
        level: "0", parent: "", isLeaf: false, expanded: true, loaded: true
    },
    {
        id: "6", name: "Bank 1", num: "1", enbl: "0",
        level: "1", parent: "5", isLeaf: true, expanded: false, loaded: true
    },
    {
        id: "7", name: "Bank 2", num: "2", enbl: "1",
        level: "1", parent: "5", isLeaf: true, expanded: false, loaded: true
    }],

  grid = $("#treegrid");
        grid.jqGrid({
            datatype: "jsonstring",
            datastr: mydata,
            colNames: ["Id", "Nombre", "Descripción", "Seleccione"],
            colModel: [
                { name: 'id', index: 'id', width: 1, hidden: true, key: true },
                { name: 'name', index: 'name', width: 300 },
                { name: 'num', index: 'acc_num', width: 80, align: "center" },
                {
                    name: 'enbl', index: 'enbl', width: 60, align: 'center',
                    formatter: 'checkbox', editoptions: { value: '1:0' },
                    formatoptions: { disabled: false }
                }
            ],
            height: 'auto',
            gridview: true,
            rowNum: 10000,
            sortname: 'id',
            treeGrid: true,
            treeGridModel: 'adjacency',
            //treedatatype: "local",
            ExpandColumn: 'name',
            caption: "Listado de Menus del sistema",
            jsonReader: {
                repeatitems: false,
                root: function (obj) { return obj; },
                page: function (obj) { return 1; },
                total: function (obj) { return 1; },
                records: function (obj) { return obj.length; }
            }
        });

        function RegistrarMenu(codigo, opcion) {
            $.colorbox({
                width: "380", height: "520", iframe: true, href: 'RegistrarMenu.aspx?codigo=' + codigo + '&opcion=' + opcion
            });
        }

        function ModificarMenu(codigo, opcion) {
            $.colorbox({
                width: "380", height: "520", iframe: true, href: 'RegistrarMenu.aspx?codigo=' + codigo + '&opcion=' + opcion
            });
        }

        function Eliminar() {
            $("#colorbox, #cboxOverlay").appendTo('form:first');
            AbrirModal('330', '210', true, false, '#yesno', false);
            $('#yesno').css("display", "block");
            return false;
        }

        function Cerrar() {
            $('#yesno').css("display", "none");
            window.CerrarModal();
        }

        function Aceptar() {
            window.location.parent.reload();
        }

    </script>

    <asp:ScriptManager ID="script" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="upFormulario" runat="server">
        <ContentTemplate>
            <div class="titulo-int">Búsqueda de Menú</div>
            <div class="div-box-gris">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="120" class="txt-campos-int">Sistema</td>
                        <td style="width:300px">
                            <asp:DropDownList runat="server" ID="ddlSistema" CssClass="field_element" Width="200"></asp:DropDownList>
                        </td>
                        <td>
                            <asp:Button ID="btnBuscar" runat="server" Text="Buscar" CssClass="skip" OnClick="btnBuscar_Click" /></td>
                    </tr>
                </table>
            </div>
            <table>
                <tr>
                    <td><input id="btnNuevo" runat="server" type="button" class="skip" onclick="RegistrarMenu(hdfMenu.value, 'nuevo')" value="Nuevo" /><br /></td>
                    <td><input id="btnModificar" runat="server" type="button" disabled="disabled" class="button2" onclick="ModificarMenu(hdfMenu.value, 'modificar')" value="Modificar" /><br /></td>
                    <td><asp:Button runat="server" ID="btnEliminar" CssClass="button2" Text="Eliminar" Enabled="false" OnClientClick="Eliminar()"/></td>
                </tr>
                <caption>
                    <br />
                </caption>
            </table>
            <div class="div-scrollTreeview">
                <asp:HiddenField ID="hdfMenu" runat="server" ClientIDMode="Static" />

                <asp:TreeView ID="trvMenu" runat="server" ImageSet="Arrows" OnSelectedNodeChanged="trvMenu_SelectedNodeChanged" ShowLines="True">
                    <HoverNodeStyle CssClass="HoverNodeStyle" />
                    <NodeStyle CssClass="NodeStyle" Font-Underline="false" HorizontalPadding="5px" />
                    <ParentNodeStyle />
                    <SelectedNodeStyle CssClass="SelectedNodeStyle" Font-Underline="True" HorizontalPadding="5px" />
                </asp:TreeView>
            </div>

              <div id="yesno" style="display: none">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="titulo-modal">Mensaje del Sistema</td>
                    </tr>
                </table>
                <br />
                <table width="100%" align="center" border="0" cellspacing="2" cellpadding="1">
                    <tr>
                        <td align="center" width="72">
                            <img alt="Interrogación" src="../../images/icon-interrogacion-modal.png" /></td>
                        <td class="" align="center" style="padding-left: 6px; padding-right: 6px;">¿Esta seguro que desea eliminar el registro?</td>
                    </tr>
                </table>
                <table width="80%" border="0" align="center" cellspacing="0" cellpadding="0">
                    <tr>
                        <td align="center">
                            <asp:Button ID="btnSi" runat="server" CssClass="skip" Text="Si" OnClick="btnSi_Click"/>
                            <asp:Button ID="btnNo" runat="server" CssClass="skip" Text="No" OnClientClick="Cerrar();" />
                        </td>
                    </tr>
                </table>
            </div>

            <div id="confirmacion" style="display: none">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="titulo-modal">Mensaje del Sistema</td>
                    </tr>
                </table>
                <br />
                <table width="100%" align="center" border="0" cellspacing="2" cellpadding="1">
                    <tr>
                        <td align="center" width="72">
                            <img alt="confirmacion" src="../../images/icon-valido.png" /></td>
                        <td class="" align="center" style="padding-left: 6px; padding-right: 6px;">El registro fue eliminado correctamente.</td>
                    </tr>
                </table>
                <table width="80%" border="0" align="center" cellspacing="0" cellpadding="0">
                    <tr>
                        <td align="center">
                            <asp:Button ID="btnAceptar" runat="server" CssClass="skip" Text="Aceptar" OnClientClick="Aceptar();" />
                        </td>
                    </tr>
                </table>
            </div>

        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
